<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Dashboard extends CI_Controller {
	
	 public function __construct()
	    {
	        parent::__construct();
	        session_start();
	        //$this->output->enable_profiler(FALSE);
	   		if (!isset($_SESSION['admin_role_id']) || $_SESSION['admin_role_id'] != 1){
		    	redirect('administration/login','refresh');
		    }
	    }
	    
	public function index()
	{
		$data['title'] = "Administration Dashboard";
		$data['left'] = 'admin/admin_left';
		$data['main'] = 'admin/dashboard';
		$this->load->vars($data);
		$this->load->view('admin/template'); 
	}
	public function getUsers() {
		$data['title'] = "User Management";
		$data['left'] = 'admin/admin_left';
		$data['main'] = 'admin/userlist';
		$data['users'] = $this->MUser->getAllUsers();
		$this->load->vars($data);
		$this->load->view('admin/template'); 
	}
	
	function createUser(){
	   	if ($this->input->post('username')){
	  		$this->MUser->addUser();
	  		$this->session->set_flashdata('message','User created');
	  		redirect('admin/dashboard/getusers','refresh');
	  	}else{
			$data['title'] = "Add new user";
			$data['left'] = 'admin/admin_left';
			$data['roles'] = $this->MUser->getRoles();
			$data['main'] = 'admin/createuser';
			$this->load->vars($data);
			$this->load->view('admin/template');    
		} 
	  }
  
	  function editUser($id=0){
		  if ($this->input->post('submit')){
		  		$this->MUser->updateUser($_POST['role_id']);
		  		$this->session->set_flashdata('message','Account updated');
				redirect('admin/dashboard/getusers','refresh');
		  		
		  	}else{
				$data['title'] = "Update User";
				$data['left'] = 'admin/admin_left';
				$data['main'] = 'admin/edituser';
				$data['roles'] = $this->MUser->getRoles();
				$data['setting'] = $this->MUser->getUser($id);
				$this->load->vars($data);
				$this->load->view('admin/template');      
			}
	  }
	  
	  function deleteUser($id){
		$this->MUser->inActiveUser($id);
		$this->session->set_flashdata('message','User is inactive');
		redirect('admin/dashboard/getusers','refresh');
	  }
	function logout(){
		unset($_SESSION['admin_role_id']);
		unset($_SESSION['admin_username']);
		$this->session->set_flashdata('error',"You've been logged out!");
		redirect('administration/login','refresh');	
	 } 
	
	
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */